<template>
  <view :style="customStyle" :class="customClass">
    <slot></slot>
    <yy-empty v-if="emptyVisible" :custom-class="emptyClass" :empty-type="emptyType" />
    <u-loadmore v-else margin-top="25" margin-bottom="25" :status="loadStatus" loading-text="数据加载中" loadmore-text="加载更多数据" nomore-text="没有更多数据" />
  </view>
</template>

<script>
  import styleMixins from '@/mixins/styleMixins'

  export default {
    name: 'yy-list',
    mixins: [styleMixins],
    props: {
      //是否请求中
      loading: { type: Boolean },
      //是否没有更多数据
      finished: { type: Boolean },
      //空数据样式
      emptyClass: {
        type: String,
        default: 'p-center'
      },
      //空数据类型
      emptyType: {
        type: String,
        default: 'history'
      },
      //数据
      list: {
        type: Array,
        default: () => {
          return []
        }
      }
    },
    data() {
      return {}
    },
    computed: {
      loadStatus() {
        const loading = this.loading
        const finished = this.finished
        if (loading) {
          return 'loading'
        }
        if (finished) {
          return 'nomore'
        }

        return 'loadmore'
      },
      emptyVisible() {
        return this.finished && !this.loading && !this.list.length
      }
    },
    methods: {}
  }
</script>

<style lang="scss" scoped></style>
